package com.study.modules.hutoolStudy;

import cn.hutool.core.util.RuntimeUtil;
import cn.hutool.core.util.StrUtil;

/**
 * hutool中的字符串工具类测试
 */
public class HutoolStrUtilTest {

    public static void main(String[] args) throws InterruptedException {
        testWindowsCmd();
        //testUUIDAndFormat();
        //testSimilar();
        //testIsBlankIfStr();
    }

    public static void testWindowsCmd() {
        String ipconfigStr = "ipconfig";
        String ipconfig1 = RuntimeUtil.execForStr(ipconfigStr);
        System.out.println(ipconfigStr + "：");
        System.out.println(ipconfig1.replaceFirst("\n", "").replace("\r\n\r\n\r", "").replace("\r\n\r\n", "\r\n")
                .replace("   ", "").replace("  ", "").replace(". ", "."));
        System.out.println("==============================\n");
        String pingCmdStr = "ping 192.168.12.52";
        String pingCmd = RuntimeUtil.execForStr(pingCmdStr);
        System.out.println(pingCmd.replaceFirst("\n", "").replace(" ", "")
                .replace("\r", "").replace("\n\n", "\n"));
    }

    /**
     * 测试生成随机字符串和字符串格式化
     */
    public static void testUUIDAndFormat() {
        String randomStr = StrUtil.uuid();
        System.out.println("随机字符串：" + randomStr);

        String formatStr = "{},{},{}";
        System.out.println(formatStr + "：" + StrUtil.format(formatStr, "d", "e"));
        System.out.println(formatStr + "：" + StrUtil.format(formatStr, "d", "e", null, false));
    }

    /**
     * 测试两个字符串的相似度
     */
    public static void testSimilar() {
        String str1 = "abc";
        String str2 = "abc";
        System.out.println("相似度小数：" + StrUtil.similar(str1, str2));
        str1 = "ab";
        str2 = "ac";
        System.out.println("相似度百分比：" + StrUtil.similar(str1, str2, 2));
    }

    /**
     * 测试字符创是否为空
     */
    public static void testIsBlankIfStr() {
        String str1 = "";
        System.out.println("空字符串：" + StrUtil.isBlankIfStr(str1));
        str1 = "\t";
        System.out.println("\\t ：" + StrUtil.isBlankIfStr(str1));
        str1 = "\n";
        System.out.println("\\n ：" + StrUtil.isBlankIfStr(str1));
        str1 = "aaa";
        System.out.println(str1 + " :" + StrUtil.isBlankIfStr(str1));
    }
}
